﻿CREATE PROCEDURE [acms].[Post_GetAllBySiteIdMenuIdAndParentPath]
	@SiteId int, 
	@MenuId int,
	@ParentPath varchar(255),
	@SiteVersion DateTime
AS
	declare @tmp DateTime
	set @tmp = acms.GetPublishDate(@SiteVersion)
	
	if not Right(@ParentPath, 1) = '/'
		set @ParentPath = @ParentPath + '/'
	
	SELECT a.*, b.ParentPath, b.PublishDate as SiteVersion
	FROM [Post_View] a
		inner join [PostPositions] b on a.Id = b.PostId and isNull(b.PublishDate, '9999/12/31') = isNull(@tmp, '9999/12/31')
	Where a.SiteId = @SiteId
		and b.ParentPath = @ParentPath
		and a.Id in (Select PostId from [PostMenu] where MenuId = @MenuId and Included = 1)
	ORDER By Sequence

RETURN 0;